package com.bqtv.sport.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.bqtv.sport.adapter.SelectAddressAdapter
import com.bqtv.sport.databinding.DialogSelectAddressBinding
import com.bqtv.sport.databinding.DialogSelectPicBinding
import com.hjq.base.BaseDialog
import com.hjq.base.BottomSheetDialog

class SelectAddressDialog {
    class Builder(context: Context) : BaseDialog.Builder<Builder>(context) {
        lateinit var addressAdapter: SelectAddressAdapter
        var binding: DialogSelectAddressBinding =
            DialogSelectAddressBinding.inflate(
                LayoutInflater.from(context),
                FrameLayout(context),
                false
            )

        init {
            setContentView(binding.root)
            setData()
        }

        fun setData(): Builder {
            binding.rcvAddress.layoutManager = LinearLayoutManager(getContext())
            addressAdapter= SelectAddressAdapter()
            binding.rcvAddress.adapter = addressAdapter
            addressAdapter.submitList(arrayListOf("上海", "北京", "广州", "深圳"))

            setOnClickListener(binding.ivClose, binding.tvAdd, binding.tvAdd2)
            return this
        }

        override fun onClick(view: View) {
            super.onClick(view)

            when (view) {
                binding.ivClose -> {
                    dismiss()
                }
                binding.tvAdd,binding.tvAdd2 -> {
                    clickResult?.onAddClick()
                }
            }
        }

        override fun createDialog(context: Context, themeId: Int): BaseDialog {
            val dialog = BottomSheetDialog(context, themeId)
            dialog.getBottomSheetBehavior().setSkipCollapsed(true)
            return dialog
        }

        var clickResult: ClickResult? = null

        interface ClickResult {
            fun onAddClick()
            fun onItemClick()
        }
    }
}